Skip to content

Fix uv PEX builder to use pex3 lock export#23227

Open
seungwoo-ji-03 wants to merge 6 commits intopantsbuild:mainfrom
seungwoo-ji-03:fix/uv-pex-lock-export
Open

Fix uv PEX builder to use pex3 lock export#23227
seungwoo-ji-03 wants to merge 6 commits intopantsbuild:mainfrom
seungwoo-ji-03:fix/uv-pex-lock-export

Conversation

@seungwoo-ji-03
Copy link
Copy Markdown

When the uv PEX builder extracts pinned requirements from a PEX-native lockfile, it previously parsed the internal JSON format directly. This broke VCS and direct URL requirements (formatted as name==version instead of name @ url), and the PEX maintainer has warned that this internal format is unsupported and may change without notice.

This PR replaces JSON parsing with pex3 lock export --format pep-751 via PexCliProcess. The exported pylock.toml is passed directly to uv pip install -r, handling VCS refs, direct URLs, extras, and platform filtering out of the box.

Follow-up to #23197 (reported by @benjyw, approach suggested by @jsirois).
Supersedes #23218.

@seungwoo-ji-03
Copy link
Copy Markdown
Author

Chose pep-751 over pip-no-hashes for two reasons:

  1. Direct URL sdist preservation: pep-751 preserves direct URL sdist references via archive sections (built from the lockfile's input requirements), while pip-no-hashes drops them to name==version in export output.

  2. VCS commit pinning: pep-751 requires commit_id on VCS artifacts, which is populated when using --pip-version 24.2 (Pants default). Locks created with older pip/Pex may fail export when VCS artifacts are missing commit_id (e.g. 20.3.4-patched); in Pants, the code falls back to transitive uv resolution in that case.

(Based on reading lock.py and pep_751.py)

Copy link
Copy Markdown
Contributor

@jsirois jsirois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seungwoo-ji-03 this looks good to me, but a few notes - the 2nd - the existence of pex3 lock export-subset, may prove useful at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants